document.querySelector('#myButton').addEventListener('click', () => {
  var text = document.querySelector('#myTextBox').value;
  // 处理用户输入
  fetch('https://api.openai.com/v1/chat/completions', {
      headers: {
          'Authorization': 'Bearer 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',
          'Content-Type': 'application/json'
      },
      method: 'POST',
      body: JSON.stringify({
            model: "gpt-3.5-turbo",
            messages: [
              {"role": "system", "content": "You are a helpful assistant."},
              {"role": "user", "content": text}
          ],
          max_tokens: 4000,
      })
  })
  .then(response => response.json())
  .then(data => {
      let responses = data['choices'][0]['message']['content'];
      document.querySelector('#responseDiv').innerHTML += '<p>User: ' + text + '</p>';
      document.querySelector('#responseDiv').innerHTML += '<p>Assistant: ' + responses + '</p>';
  })
  .catch(error => {
      console.log("API错误: ", error);
      // 在这里处理错误，比如将错误信息显示给用户
      document.querySelector('#responseDiv').innerHTML += '<p>Error: ' + error.toString() + '</p>';
  });
});